package utils;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.RandomAccessFile;
import java.io.Reader;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Properties;
import java.util.Set;

public class Util {
	private static String ERROR_MESSAGE ="";
	public static void main(String[] args) throws FileNotFoundException, IOException {
	
		File file = creatfile("E:/软件_系统/win软件/1/1/1/1/2/sys.text/");
		//String readtxt = readtxt(file);
		//copyfile("E:/软件_系统/win软件/1/1/1/1/2/sys.text/","E:/软件_系统/win软件/1/1/1/sys.text");
		writetxt(file,"  asldfjlaskjdfjk ");
	}
	  public static void listAll(File path){
		  File[] listFiles = path.listFiles();
		  for (File file : listFiles) {
			if(file.isDirectory()){
				listAll(file);
			}else{
				System.out.println(" :"+file.getAbsolutePath());
			}
		}
	  }
	public static void generateIamge(String path){
		
	}
	/*public static void copyfile(String src,String dest ,boolean overlay){
		File file = new File(src);
		if(!file.exists()){
			ERROR_MESSAGE ="not ";
			return false;
		}
		
			
		return overlay;
	}*/
	public static void copyfile(String src,String dest) throws IOException{
		InputStream in = new FileInputStream(src);
		OutputStream out = new FileOutputStream(dest);
		byte[] bt = new byte[1024];
		int readsize = 0; 
		while((readsize = in.read(bt))!=-1){
			out.write(bt, 0, readsize);
		}
		out.close();
	}
	public static void  writeProperties(File file,Map<String,String> map){
		Properties properties = new Properties();
		try {
			properties.load(new FileInputStream(file));
			Set<Entry<String, String>> entrySet = map.entrySet();
			for (Entry<String, String> entry : entrySet) {
				properties.setProperty(entry.getKey(),entry.getValue());
			}
			FileOutputStream fileOutputStream = new FileOutputStream(file);
			properties.store(fileOutputStream, "修改下");
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}
	
	public static File creatfile(String path){
		File file = new File(path);
		if(!file.exists()){
			new File(path).getParentFile().mkdirs();
		}
		File file2 = new File(path);
		try {
			file2.createNewFile();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return file2;
	}
	public HashMap<String,String> getDataMap(){
		HashMap<String,String> hashMap = new HashMap();
		hashMap.put("4", "4v");
		hashMap.put("5", "5v");
		return hashMap;
	}
	public String getDataTxt(){
		String txt="hhhhhhhhh";
		return txt;
	}
	public static String readtxt(File file) throws IOException{
		Reader in = new FileReader(file);
		BufferedReader br = new BufferedReader(in);
		String str ="";
		String read ="";
		while ((read =br.readLine())!=null){
			str += read+"\r\n";
		}
		System.out.println(str);
		return str;
	}
	public static String writetxt(File file,String newstxt) throws IOException{
		RandomAccessFile ra = new RandomAccessFile(file, "rw");
		String readtxt = readtxt(file);
		readtxt += newstxt;
		ra.writeBytes(readtxt);
		ra.close();
		return null;
	}
	
}

